#!/bin/bash 


./org1peer0.sh lifecycle chaincode package mycc.tar.gz --path github.com/chaincode/test --lang golang --label mycc_1

./org1peer0.sh lifecycle chaincode install mycc.tar.gz 
./org2peer0.sh lifecycle chaincode install mycc.tar.gz

./org1peer0.sh lifecycle chaincode approveformyorg -o orderer0.orderer.sample.com:7050 --channelID mychannel --name mycc --version 0.1 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile $CA_FILE
./org2peer0.sh lifecycle chaincode approveformyorg -o orderer0.orderer.sample.com:7050 --channelID mychannel --name mycc --version 0.1 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile $CA_FILE

./org1peer0.sh lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 0.1 --sequence 1 --tls --cafile $CA_FILE --output json

# chaincode commit 
./org1peer0.sh lifecycle chaincode commit -o orderer0.orderer.sample.com:7050 --channelID mychannel --name mycc --version 0.1 --sequence 1 --tls --cafile $CA_FILE --peerAddresses peer0.org1.sample.com:7051 --tlsRootCertFiles $Org1Tls --peerAddresses peer0.org2.sample.com:7051 --tlsRootCertFiles $Org2Tls

./org1peer0.sh lifecycle chaincode querycommitted --channelID mychannel --name mycc --cafile $CA_FILE

# init 
./org1peer0.sh chaincode invoke -o orderer0.orderer.sample.com:7050 --isInit --tls --cafile $CA_FILE -C mychannel -n mycc --peerAddresses peer0.org1.sample.com:7051 --tlsRootCertFiles $Org1Tls --peerAddresses peer0.org2.sample.com:7051 --tlsRootCertFiles $Org2Tls -c '{"Args":["Init"]}' --waitForEvent

# invoke 
./org1peer0.sh chaincode invoke -o orderer0.orderer.sample.com:7050 --tls --cafile $CA_FILE -C mychannel -n mycc --peerAddresses peer0.org1.sample.com:7051 --tlsRootCertFiles $Org1Tls --peerAddresses peer0.org2.sample.com:7051 --tlsRootCertFiles $Org2Tls -c '{"Args":["set","b","500"]}' --waitForEvent

./org1peer0.sh chaincode invoke -o orderer0.orderer.sample.com:7050 --tls --cafile $CA_FILE -C mychannel -n mycc --peerAddresses peer0.org1.sample.com:7051 --tlsRootCertFiles $Org1Tls --peerAddresses peer0.org2.sample.com:7051 --tlsRootCertFiles $Org2Tls -c '{"Args":["set","g","3200"]}' --waitForEvent
